import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/16 11:41
 * @description:
 */
public class LCR186 {
    public boolean checkDynasty(int[] places) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < places.length; i++) {
            if (places[i] != 0) {
                max = Math.max(max, places[i]);
                min = Math.min(min, places[i]);
                if (!set.contains(places[i])) {
                    set.add(places[i]);
                } else {
                    return false;
                }
            }
        }
        return max - min <= 4;
    }

    public static void main(String[] args) {
        LCR186 lcr = new LCR186();
//        System.out.println(lcr.checkDynasty(new int[]{0, 6, 9, 0, 7}));
        System.out.println(lcr.checkDynasty(new int[]{7, 8, 9, 10, 11}));
        System.out.println(lcr.checkDynasty(new int[]{0, 0, 2, 2, 5}));
    }
}
